package com.umgsai.thread.thread02;

public class MyRunnable {
	static private Object lock = new Object();
	static private Runnable runnable1 = new Runnable() {
		
		@Override
		public void run() {
			synchronized (lock) {
				System.out.println(System.currentTimeMillis() + " begin wait");
				try {
					lock.wait(5000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println(System.currentTimeMillis() + " end wait");
			}
		}
	};
	private static Runnable runnable2 = new Runnable() {
		
		@Override
		public void run() {
			synchronized (lock) {
				System.out.println(System.currentTimeMillis() + " begin notify");
				lock.notify();
				System.out.println(System.currentTimeMillis() + " end notify");
			}
		}
	};
	
	public static void main(String[] args) throws InterruptedException {
		Thread thread1 = new Thread(runnable1);
		thread1.start();
		Thread.sleep(2000);
		Thread thread2 = new Thread(runnable2);
		thread2.start();
	}
}
